﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：PurchaseGoodsSetCompany.cs
    // 文件功能描述：设置采购目录的配送企业
    // 创建标识：吕海乐2009-05-15
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：没有使用 2009-6-5 李刚
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using System.Data;

namespace HZ.DrugTrade.Web.Hospitals.Procurement
{
    [Obsolete("该页面不再使用")]
    public partial class PurchaseGoodsSetCompany : BasePage
    {
        public PurchaseGoodsSetCompany()
        {
            this.ModuleNo = "";
        }

        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        IBLL_HospitalProcureCatalog ihp = Factory.BLL_HospitalProcureCatalog();
        IBLL_Distribution id = Factory.BLL_Distribution();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //绑定所有项目
                ProcurementProject procurementProject = new ProcurementProject();
                procurementProject.ProcureStartTimeFrom = Convert.ToDateTime("1890-01-01");
                procurementProject.ProcureStartTimeTo = Convert.ToDateTime("2099-12-31");
                procurementProject.ProcureEndTimeFrom = Convert.ToDateTime("2000-01-01");
                procurementProject.ProcureEndTimeTo = Convert.ToDateTime("2099-12-31");
                int temp;
                IList<ProcurementProject> projectList = ipb.GetProjectByWhere(procurementProject, 1, 0, out temp);
                ddlProject.DataSource = projectList;
                ddlProject.DataTextField = "ProjectName";
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataBind();
                ListItem item = new ListItem();
                item.Text = Constants.ALL_ITEM_TEXT;
                item.Value = Constants.ALL_ITEM_VALUE;
                ddlProject.Items.Insert(0, item);
                //绑定采购目录
                setBind();
            }
        }

        /// <summary>
        /// 绑定医疗机构自身的采购目录
        /// </summary>
        private void setBind()
        {
            //绑定所有医疗机构采购目录
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            Model.Query.HospitalProcureCatalog qHospitalCatalog = GetCondition();
            IList<Model.View.HospitalProcureCatalog> hosiptalCatalogList = ihp.GetHospitalProcureCatalog(qHospitalCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            DataTable hospitalCatalog = HZ.Data.ModelConvert.GetDataTableFromModel(hosiptalCatalogList);
            hospitalCatalog.Columns.Add("Company_PS");

            //从配送关系中取出配送企业
            Model.Query.DistributionRelation qDistributionRelation = new HZ.DrugTrade.Model.Query.DistributionRelation();
            qDistributionRelation.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            qDistributionRelation.ProcureCatalog_IsUsing = true;
            qDistributionRelation.DistributionIsUsing = true;
            qDistributionRelation.Hospital_IsUsing = true;
            qDistributionRelation.SortFields = "AddTime asc";
            IList<Model.View.DistributionRelation> distributionList = id.GetDistributionByWhere(qDistributionRelation, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            DataTable distributionCatalog = HZ.Data.ModelConvert.GetDataTableFromModel(distributionList);
            for (int i = 0; i < hospitalCatalog.Rows.Count; i++)
            {
                for (int j = distributionCatalog.Rows.Count - 1; j >= 0; j--)
                {
                    if (hospitalCatalog.Rows[i]["ProcureCatalogID"].Equals(distributionCatalog.Rows[j]["ProcureCatalogID"]))
                    {
                        hospitalCatalog.Rows[i]["Company_PS"] = distributionCatalog.Rows[j]["CompanyName_PS"];
                    }
                    else
                    {
                        hospitalCatalog.Rows[i]["Company_PS"] = "请设置配送企业";
                    }
                }
            }
            gvwProduceCatalog.PageSize = AspNetPager1.PageSize;
            gvwProduceCatalog.DataSource = hospitalCatalog;
            gvwProduceCatalog.DataBind();
        }

        /// <summary>
        /// 获取查询条件
        /// </summary>
        /// <returns></returns>
        private Model.Query.HospitalProcureCatalog GetCondition()
        {
            Model.Query.HospitalProcureCatalog procureCatalog = new HZ.DrugTrade.Model.Query.HospitalProcureCatalog();
            procureCatalog.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            procureCatalog.Companyname_Sc = txtProduceCompany_SC.Text.Trim();
            procureCatalog.GoodsName = txtGoodsName.Text.Trim();
            procureCatalog.Outlookc = txtOutLook.Text.Trim();
            //procureCatalog.Pack = txtPack.Text.Trim();
            procureCatalog.ProjectID = ddlProject.SelectedItem.Value;
            procureCatalog.Unit = txtUnit.Text.Trim();
            //if (HZ.Common.MyValidate.IsNumeric(txtFactor.Text.Trim()))
            //{
            //    procureCatalog.Factor = Convert.ToInt32(txtFactor.Text.Trim());
            //}
            procureCatalog.SortFields = "AddTime DESC";

            procureCatalog.Hospital_IsUsing = true;
            return procureCatalog;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            setBind();
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            setBind();
        }

        /// <summary>
        /// 简单查询与高级查询间的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据
                //txtFactor.Text = "";
                txtGoodsName.Text = "";
                //txtPack.Text = "";
                txtProduceCompany_SC.Text = "";
                txtUnit.Text = "";
                ddlProject.SelectedIndex = -1;
            }
        }
    }
}
